package com.ruoyi.system.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.controller.es.EsUnService;
import com.ruoyi.system.controller.es.dto.EsSearch;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.vo.AdminHomeCountVo;
import com.ruoyi.system.domain.vo.AdminHomehexinCountVo;
import com.ruoyi.system.domain.vo.LabelValuetVo;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/adminhome")
public class HomeAdminController extends BaseController {
    @Autowired
    private IFyDataService fyDataService;
    @Autowired
    private IFyPeopleService fyPeopleService;
    @Autowired
    private IFyProjectService fyProjectService;
    @Autowired
    private IFyResourcesService fyResourcesService;
    @Autowired
    private IFyPolicyService fyPolicyService;
    @Autowired
    private IFyInfoService fyInfoService;
    @Autowired
    private EsUnService esUnService;
    @GetMapping("/datascount")
    public AjaxResult datascount()
    {
        AdminHomeCountVo adminHomeCountVos=fyDataService.selectAdminHomecountShujuzonglan();
        adminHomeCountVos.setXiangmuleibie(10);
        AdminHomehexinCountVo homehexinCountVo=fyDataService.selectAdminHomecountHexinShujuzonglan();

        Map<String,Object> map=new HashMap<>();
        List<LabelValuetVo> zyzl=new ArrayList<>();
        zyzl.add(new LabelValuetVo(adminHomeCountVos.getZiyuanzongliang(), "资源总量"));
        zyzl.add(new LabelValuetVo(adminHomeCountVos.getHexinziyyuanzongliang(), "核心资源总量"));
        zyzl.add(new LabelValuetVo(adminHomeCountVos.getKuozhanziyuan(), "扩展资源总量"));
        zyzl.add(new LabelValuetVo(adminHomeCountVos.getXiangmuleibie(), "项目类别"));
        zyzl.add(new LabelValuetVo(adminHomeCountVos.getXiangmushu(), "非遗项目数"));
        zyzl.add(new LabelValuetVo(adminHomeCountVos.getChuanchengren(), "传承人总数"));
        map.put("zyzl",zyzl);
        List<LabelValuetVo> hxzyzl=new ArrayList<>();
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getGuojiaji(), "国家项目总数"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getQuji(), "省级项目总数"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getShiji(), "市级项目总数"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getChuantongyiyao(), "传统医药"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getChuantongjiyi(), "传统技艺"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getTiyuzaji(), "传统体育、游艺与杂技"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getMinsu(), "民俗"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getChuantongwudao(), "传统舞蹈"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getChuantongmeishu(), "传统美术"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getChuantongyinyue(), "传统音乐"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getChuantongxiju(), "传统戏剧"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getQuyi(), "曲艺"));
        hxzyzl.add(new LabelValuetVo(homehexinCountVo.getMinjinwenxue(), "民间文学"));
        map.put("hxzyzl",hxzyzl);

        return AjaxResult.success(map);
    }

    @GetMapping("/addEsProject")
    public AjaxResult addEsProject()
    {
        List<FyProject> projectList = fyProjectService.selectFyProjectList(null);
        projectList.stream().forEach(l->{
            EsSearch esSearch=new EsSearch();
            esSearch.setId(l.getProjectId());
            esSearch.setLanmu("资源-项目名录");
            esSearch.setLanmuId(1);
            esSearch.setTitle(l.getProjectName());
            esSearch.setContent(l.getProjectBrief());
            esSave(esSearch);
        });

        return AjaxResult.success();
    }
    @GetMapping("/addEsPeople")
    public AjaxResult addEsPeople()
    {
        List<FyPeople> peopleList=fyPeopleService.selectFyPeopleList(null);
        peopleList.stream().forEach(l->{
            EsSearch esSearch=new EsSearch();
            esSearch.setId(l.getPeopleId());
            esSearch.setLanmu("资源-非遗传承人");
            esSearch.setLanmuId(2);
            esSearch.setTitle(l.getPeopleName());
            esSearch.setContent(l.getPeopleBrief());
            esSave(esSearch);
        });
        return AjaxResult.success();
    }
    @GetMapping("/addEsResources")
    public AjaxResult addEsResources()
    {

        //.limit(100)
        List<FyResources> resourcesList=fyResourcesService.selectFyResourcesList(null);
        resourcesList.stream().forEach(l->{
            EsSearch esSearch=new EsSearch();
            esSearch.setId(l.getReId());
            esSearch.setLanmu("资源-扩展资源");
            esSearch.setLanmuId(3);
            esSearch.setTitle(l.getFileName());
            esSearch.setContent(l.getType());
            esSave(esSearch);
        });
        return AjaxResult.success();
    }
    @GetMapping("/addEsPolicy")
    public AjaxResult addEsPolicy()
    {

        List<FyPolicy> policyList=fyPolicyService.selectFyPolicyList(null);
        policyList.stream().forEach(l->{
            EsSearch esSearch=new EsSearch();
            esSearch.setId(l.getPolicyId());
            esSearch.setLanmu("政策");
            esSearch.setLanmuId(4);
            esSearch.setTitle(l.getPolicyTitle());
            esSearch.setContent(l.getContent());
            esSave(esSearch);
        });
        return AjaxResult.success();
    }
    @GetMapping("/addEsInfo")
    public AjaxResult addEsInfo()
    {

        List<FyInfo> infoList=fyInfoService.selectFyInfoList(null);
        infoList.stream().forEach(l->{
            EsSearch esSearch=new EsSearch();
            esSearch.setId(l.getInfoId());
            esSearch.setLanmu("资讯");
            esSearch.setLanmuId(5);
            esSearch.setTitle(l.getInfoTitle());
            esSearch.setContent(l.getContent());
            esSave(esSearch);
        });
        return AjaxResult.success();
    }

    private void esSave(EsSearch esSearch) {
        esUnService.save(esSearch);
    }
}
